import { Component, OnInit,Input,Output, EventEmitter } from '@angular/core';

@Component({
  selector: 'el-pagination-jump',
  templateUrl: './jump.component.html'
})
export class JumpComponent implements OnInit {
  @Input() model: number = 0;
  @Input()   max: number = 0;
  @Output()  next: EventEmitter<number> = new EventEmitter();
  constructor() { }

  ngOnInit(): void {
  }


  nextPageNumber(page:number, max:number) {
    if (page <= 1)
            return 1;
        if (page >= max)
            return max;
        return page;
  }

  changeHandle(event:any){
    var nextValue = event.target.value
    if (Number.isNaN(+nextValue))
            return;
        var /** @type {?} */ next = this.nextPageNumber(+nextValue, this.max);
        var /** @type {?} */ pre = this.model;
        this.model = Math.round(next);
        this.next.emit(this.model - pre);
  }
}
